# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=tepl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-${_realname}-docs")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}5")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}5")
pkgver=6.4.0
pkgrel=2
pkgdesc="Library that eases the development of GtkSourceView-based text editors and IDEs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://wiki.gnome.org/Projects/Tepl"
license=('spdx:LGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-amtk"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview4"
         "${MINGW_PACKAGE_PREFIX}-icu")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('5e56b20669d0cf05fa1d64b58c8c342c59158122dc518100d093d59df9b87321')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --default-library=both \
    --buildtype=plain \
    -D gtk_doc=true \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/meson.exe test --print-errorlogs || true
}

package_tepl() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "${srcdir}/build-${MSYSTEM}" --destdir "${pkgdir}"

  mkdir -p dest${MINGW_PREFIX}/share
  mv "${pkgdir}${MINGW_PREFIX}"/share/gtk-doc dest${MINGW_PREFIX}/share/gtk-doc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSES/LGPL-3.0-or-later.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LGPL-3.0-or-later.txt"
}

package_tepl-docs() {
  pkgdesc+=" (documentation)"
  depends=()
  conflicts=()
  replaces=()

  mv dest/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
